﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace MeetingMan
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();

            int diff = DateTime.Now.Minute > 30 ? 60 - DateTime.Now.Minute : 30 - DateTime.Now.Minute;
            DateTime defaultStartTime = DateTime.Now.AddMinutes(diff);
            defaultStartTime = new DateTime(defaultStartTime.Year, defaultStartTime.Month, defaultStartTime.Day, defaultStartTime.Hour, defaultStartTime.Minute, 0);
            dpStartTime.Value = defaultStartTime;
            dpEndTime.Value = defaultStartTime.AddMinutes(30);
        }

        private void cbRecurrence_CheckedChanged(object sender, EventArgs e)
        {
            gbRecurrence.Visible = cbRecurrence.Checked;
        }

        private void dpEndTime_ValueChanged(object sender, EventArgs e)
        {
            tbDuration.Text = Convert.ToInt32( dpEndTime.Value.Subtract(dpStartTime.Value).TotalMinutes).ToString();
        }

        private void ChangeEndDate(object sender, EventArgs e)
        {
            try
            {
                int duration = 0;
                if (!string.IsNullOrEmpty(tbDuration.Text))
                {
                   duration = Convert.ToInt32(tbDuration.Text.Trim());
                }
                DateTime startTime = dpStartTime.Value;
                dpEndTime.Value = startTime.AddMinutes(duration);
            }
            catch (Exception exp)
            {
                MessageBox.Show(this, "Invalid Duration", "Please enter valid number for duration.", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            FavorMeetingRooms favorMeetingRoomDialog = new FavorMeetingRooms();
            favorMeetingRoomDialog.ShowDialog(this);
        }




    }
}
